#include <iostream>
#include <vector>
#include <string>
using namespace std;
class Solution {
public:
    vector<string> letterCasePermutation(string s) {
        vector<string> result;
        backtrack(s, result, 0);
        return result;
    }
private:
    void backtrack(string s, vector<string>& result, int index) {
        if (index == s.length()) { result.push_back(s); return; }
        if (isalpha(s[index])) {
            backtrack(s, result, index + 1);
            s[index] = islower(s[index]) ? toupper(s[index]) : tolower(s[index]);
            backtrack(s, result, index + 1);
        }
        else {
            backtrack(s, result, index + 1);
        }
    }
};